SHELL = @SHELL@
@SUBMAKE@

top_srcdir = @top_srcdir@
srcdir = @srcdir@
top_builddir = ../..
subdir = tools/lib
conf_auxdir = @conf_auxdir@

prefix = @prefix@
bindir = @bindir@
libdir = @libdir@
includedir = @includedir@
toolincludedir = $(includedir)/clicktool
HOST_TOOLS = @HOST_TOOLS@

VPATH = .:$(top_srcdir)/$(subdir):$(top_srcdir)/tools/lib:$(top_srcdir)/lib

CC = @CC@
CXX = @CXX@
AR_CREATE = @AR@ @AR_CREATEFLAGS@
RANLIB = @RANLIB@
BUILD_CC = @BUILD_CC@
BUILD_CXX = @BUILD_CXX@
BUILD_AR_CREATE = @BUILD_AR@ @AR_CREATEFLAGS@
BUILD_RANLIB = @BUILD_RANLIB@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL@ -m 644
INSTALL_DATA_IF_CHANGED = @INSTALL_IF_CHANGED@ -m 644
mkinstalldirs = $(conf_auxdir)/mkinstalldirs

.SUFFIXES:
.SUFFIXES: .S .c .cc .o .bo .s

.c.o:
	$(COMPILE) -c $<
	@-/bin/mv $*.d $*.hd
.s.o:
	$(COMPILE) -c $<
	@-/bin/mv $*.d $*.hd
.S.o:
	$(COMPILE) -c $<
	@-/bin/mv $*.d $*.hd
.cc.o:
	$(CXXCOMPILE) -c $<
	@-/bin/mv $*.d $*.hd
.c.bo:
	$(BUILD_COMPILE) -c $< -o $@
	@-sed 's/\.o:/\.bo:/' < $*.d > $*.bd; /bin/rm -f $*.d
.cc.bo:
	$(BUILD_CXXCOMPILE) -c $< -o $@
	@-sed 's/\.o:/\.bo:/' < $*.d > $*.bd; /bin/rm -f $*.d


OBJS = string.o straccum.o \
	bitvector.o vectorv.o vectori.o hashmapi.o bighashmap_arena.o \
	ipaddress.o etheraddress.o \
	timestamp.o error.o \
	elementt.o eclasst.o routert.o runparse.o variableenv.o \
	lexert.o lexertinfo.o driver.o \
	confparse.o archive.o processingt.o etraits.o elementmap.o \
	userutils.o md5.o toolutils.o clp.o @LIBOBJS@ @EXTRA_TOOL_OBJS@
BUILDOBJS = $(patsubst %.o,%.bo,$(OBJS))

CPPFLAGS = @CPPFLAGS@ -DCLICK_TOOL
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
DEPCFLAGS = @DEPCFLAGS@

DEFS = @DEFS@
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
	-I$(srcdir)
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) $(DEPCFLAGS)
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(DEPCFLAGS)
BUILD_CXXCOMPILE = $(BUILD_CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) $(DEPCFLAGS)
BUILD_COMPILE = $(BUILD_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(DEPCFLAGS)

ifeq ($(HOST_TOOLS),mixed)
all: libclicktool.a libclicktool_build.a
endif
ifeq ($(HOST_TOOLS),build)
all: libclicktool_build.a
endif
ifeq ($(HOST_TOOLS),host)
all: libclicktool.a
endif

libclicktool.a: Makefile $(OBJS)
	$(AR_CREATE) libclicktool.a $(OBJS)
	$(RANLIB) libclicktool.a
libclicktool_build.a: Makefile $(BUILDOBJS)
	$(BUILD_AR_CREATE) libclicktool_build.a $(BUILDOBJS)
	$(BUILD_RANLIB) libclicktool_build.a

Makefile: $(srcdir)/Makefile.in
	cd $(top_builddir) \
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_ELEMLISTS=no CONFIG_HEADERS= $(SHELL) ./config.status

DEPFILES := $(wildcard *.hd *.bd)
ifneq ($(DEPFILES),)
include $(DEPFILES)
endif

install: install-local
install-lib install-local: libclicktool.a install-include
	$(mkinstalldirs) $(DESTDIR)$(libdir)
	$(INSTALL) libclicktool.a $(DESTDIR)$(libdir)/libclicktool.a
install-include:
	$(mkinstalldirs) $(DESTDIR)$(toolincludedir)
	$(INSTALL_DATA_IF_CHANGED) $(srcdir)/*.hh $(DESTDIR)$(toolincludedir)
uninstall:
	/bin/rm -f $(DESTDIR)$(libdir)/libclicktool.a
	cd $(srcdir); for i in *.hh; do /bin/rm -f $(DESTDIR)$(toolincludedir)/$$i; done

clean:
	rm -f *.d *.hd *.bd *.o *.bo libclicktool.a libclicktool_build.a
distclean: clean
	-rm -f Makefile

.PHONY: all clean distclean \
	install install-lib install-local install-include uninstall
